function getUserInf() {
    $.ajax({
        url: "/my/userinfo",
        // headers: {
        //     Authorization: localStorage.getItem("token") || ""
        // },
        success(res) {
            console.log(res);
            if (res.status !== 0) {
                return layui.layer.msg()
            }
            renderAvatar(res.data)
        }
    })
}

function renderAvatar(data) {
    let name = data.nickname || data.username
    $("#welcome").html("欢迎&nbsp;" + name)
    if (data.user_pic !== null) {
        $(".layui-nav-img").attr("src", data.user_pic).show()
        $(".text-avatar").hide()
    } else {
        let first = name[0].toUpperCase()
        $(".layui-nav-img").hide()
        $(".text-avatar").html(first).show()
    }
}

$(function () {
    getUserInf()

    $("#btn-logout").on("click", function () {
        layui.layer.confirm("你确定要推出么", {
            icon: 3,
            title: "提示"
        }, function (index) {
            localStorage.removeItem("token");
            location.href = "/login.html"
            layui.layer.close(index)
        })
    })
})